package com.qf.realms;

import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.SimpleAuthenticationInfo;
import org.apache.shiro.authz.AuthorizationInfo;
import org.apache.shiro.realm.AuthorizingRealm;
import org.apache.shiro.subject.PrincipalCollection;
import org.apache.shiro.util.ByteSource;

/**
 * IntelliJ IDEA -> shiro1125
 * 2019/11/26 10:43
 *
 * @author zmyao
 * 别看，我是渣渣。
 */
public class RealmB extends AuthorizingRealm {
    //授权
    @Override
    protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principalCollection) {
        return null;
    }
//认证
    @Override
    protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
        String  username = (String)token.getPrincipal();
        //根据数据库查询，对应的密码
        String truePassword = "876d21fb08f5bf82f1167fbfa357c02e";
        System.out.println("username*************************"+username);
        String salt = "agte";
        return  new SimpleAuthenticationInfo(username,truePassword, ByteSource.Util.bytes(salt),"myRealm");
    }
}
